<?php require_once('Connections/locamedicadmin.php'); ?>

<?php include('userValidation.php'); ?>

<?php require_once('functions.php'); ?>

<?php
$currentPage = $_SERVER["PHP_SELF"];

$maxRows_csss = 20;
$pageNum_csss = 0;

if (isset($_GET['pageNum_csss'])) {
  $pageNum_csss = $_GET['pageNum_csss'];
}
$startRow_csss = $pageNum_csss * $maxRows_csss;

mysql_select_db($database_locamedicadmin, $locamedicadmin);
$query_csss = "SELECT * from csre_csss where deleted = 0";


if (isset($_POST['search']) || isset($_GET['search'])) {

	if (isset($_POST['filter'])) { $filter = addslashes($_POST['filter']); } else { $filter = addslashes($_GET['filter']); }

	if (isset($_POST['filterValue'])) { $filterValue = addslashes($_POST['filterValue']); } else { $filterValue = addslashes($_GET['filterValue']); }

	$where = "";
	if ($filter == "name") {
		$where = " and name like '%" . $filterValue .  "%' ";
	} else if ($filter == "contact_name") {
		$where = " and contact_name like '%" . $filterValue .  "%' ";
	} else if ($filter == "contact_phone") {
		$where = " and contact_phone like '%" . $filterValue .  "%' ";
	}
	
	$query_csss = $query_csss . $where;

	$order = "";
	$orderby = "";
	
	if (isset($_POST['order']) && isset($_POST['orderby'])) {
	
		$order = $_POST['order'];
		$orderby = $_POST['orderby'];
		
		$query_csss = $query_csss . " order by " . $order . " " . $orderby;
	
	}	

}




$query_limit_csss = sprintf("%s LIMIT %d, %d", $query_csss, $startRow_csss, $maxRows_csss);
$csss = mysql_query($query_limit_csss, $locamedicadmin) or die(mysql_error());
$row_csss = mysql_fetch_assoc($csss);

if (isset($_GET['totalRows_csss'])) {
  $totalRows_csss = $_GET['totalRows_csss'];
} else {
  $all_csss = mysql_query($query_csss);
  $totalRows_csss = mysql_num_rows($all_csss);
}
$totalPages_csss = ceil($totalRows_csss/$maxRows_csss)-1;

$queryString_csss = "";
if (!empty($_SERVER['QUERY_STRING'])) {
  $params = explode("&", $_SERVER['QUERY_STRING']);
  $newParams = array();
  foreach ($params as $param) {
    if (stristr($param, "pageNum_csss") == false && 
        stristr($param, "totalRows_csss") == false) {
      array_push($newParams, $param);
    }
  }
  if (count($newParams) != 0) {
    $queryString_csss = "&" . htmlentities(implode("&", $newParams));
  }
}
$queryString_csss = sprintf("&totalRows_csss=%d%s", $totalRows_csss, $queryString_csss);
?>


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>Locamedic CSRE Admin</title>
<link href="locamedicadmin.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="page">

	<?php include('sidebar.php'); ?>
	
	<!-- end sidebar -->
	<div id="content">
		<div align="center"><img src="images/page_image_5.jpg" alt="" /></div>
	  <div class="boxed">
		<h1 class="title2">CSSS List</h1>
		<br />

		<form action="CSSS_list.php" method="post">
			<input type="hidden" value="search" name="search" />
			<table cellpadding="5" class="text">
				<tr>
					<td width="150">Rechercher pour:</td>
					<td width="150">Par:</td>
					<td>
						Trier par
					</td>
					<td>
						&nbsp;
					</td>
				</tr>
				<tr>
					<td><input type="text" name="filterValue" id="filterValue" value="<?php echo $filterValue; ?>" 
						<?php if ($filter == 'category') { echo "disabled=\"disabled\""; } ?> /></td>
					<td>
						<select style="width: 110px;" class="text" name="filter" id="filter">
							<option <?php if ("name" == $filter) { echo "selected=\"selected\""; } ?> value="name">Nom</option>
							<option <?php if ("contact_name" == $filter) { echo "selected=\"selected\""; } ?> value="contact_name">Nom du contact</option>
							<option <?php if ("contact_phone" == $filter) { echo "selected=\"selected\""; } ?> value="contact_phone">
								Contact t&eacute;l&eacute;phonique
							</option>
							<option <?php if ("email" == $filter) { echo "selected=\"selected\""; } ?> value="email">Email</option>
						</select>
					</td>
					<td>
						<select name="order">
							<option <?php if ($order == 'name') { echo "selected='selected' "; } ?> value="name">Nom</option>
							<option <?php if ($order == 'contact_name') { echo "selected='selected' "; } ?> value="contact_name">Contact Nom</option>
						</select>
					</td>
					<td>
						<select name="orderby">
							<option <?php if ($orderby == 'asc') { echo "selected='selected' "; } ?> value="asc">&uarr;</option>
							<option <?php if ($orderby == 'desc') { echo "selected='selected' "; } ?>value="desc">&darr;</option>
						</select>
					</td>
				</tr>
				<tr>
					<td colspan="5">												
						<div class="botonera">
							<input type="submit" value="Rechercher" />
						</div>
					</td>
				</tr>
			</table>
		</form>

		<br />

		<?php if ($totalRows_csss > 0) { ?>		
		
		<table cellpadding="5" cellspacing="0">
		  <thead>
		    <td>Nom</td>
			<td>Contact nom</td>
			<td>Contact phone</td>
			<td>Email</td>
			<td>Enabled</td>
			<td width="5%"></td>
			<td width="5%"></td>
		 </thead>
		  <?php do { ?>
			<tr>
			  <td><?php echo $row_csss['name']; ?></td>
			  <td><?php echo $row_csss['contact_name']; ?></td>
			  <td><?php echo $row_csss['contact_phone']; ?></td>
			  <td><?php echo $row_csss['email']; ?></td>
			  <td><?php if ($row_csss['enabled']) { echo "OUI"; } else { echo "NON"; } ?></td>
			  <td>
				<a href="CSSS_edit.php?csss_id=<?php echo $row_csss['csss_id']; ?>">
					<img src="images/1307905892_desktop.png" alt="Modifier" border="0" />
				</a>
			  </td>
			  <td>
				<a href="CSSS_delete.php?csss_id=<?php echo $row_csss['csss_id']; ?>"
					onclick="return confirm('Etes-vous sûr de vouloir supprimer ce registre?');">
					<img src="images/1307905898_edit-trash.png" alt="Supprimer" border="0" />
				</a>
			  </td>
			</tr>
			<?php } while ($row_csss = mysql_fetch_assoc($csss)); ?>
		</table>
		<table>
			<tr>
				<td align="center">
					Rows <?php echo ($startRow_csss + 1) ?> to <?php echo min($startRow_csss + $maxRows_csss, $totalRows_csss) ?> of <?php echo $totalRows_csss ?>
				</td>
			</tr>
		</table>
		       

		
		<table border="0" width="50%" align="center">
          <tr>
            <td width="23%" align="center"><?php if ($pageNum_csss > 0) { // Show if not first page ?>
                  <a href="<?php printf("%s?pageNum_csss=%d%s", $currentPage, 0, $queryString_csss); ?>"><img src="images/resultset_first.png" border=0></a>
                  <?php } // Show if not first page ?>
            </td>
            <td width="31%" align="center"><?php if ($pageNum_csss > 0) { // Show if not first page ?>
                  <a href="<?php printf("%s?pageNum_csss=%d%s", $currentPage, max(0, $pageNum_csss - 1), $queryString_csss); ?>"><img src="images/resultset_previous.png" border=0></a>
                  <?php } // Show if not first page ?>
            </td>
            <td width="23%" align="center"><?php if ($pageNum_csss < $totalPages_csss) { // Show if not last page ?>
                  <a href="<?php printf("%s?pageNum_csss=%d%s", $currentPage, min($totalPages_csss, $pageNum_csss + 1), $queryString_csss); ?>"><img src="images/resultset_next.png" border=0></a>
                  <?php } // Show if not last page ?>
            </td>
            <td width="23%" align="center"><?php if ($pageNum_csss < $totalPages_csss) { // Show if not last page ?>
                  <a href="<?php printf("%s?pageNum_csss=%d%s", $currentPage, $totalPages_csss, $queryString_csss); ?>"><img src="images/resultset_last.png" border=0></a>
                  <?php } // Show if not last page ?>
            </td>
          </tr>
        </table>
		<?php } else { ?>
		<table>
			<tr>
				<td>No csss found</td>
			</tr>
		</table>
		<?php } ?>
        <div class="botonera">
			<input type="button" onclick="window.location='CSSS_add.php';" value="Add CSSS" />
		</div>
		
	  </div>
  </div>
	<!-- end content -->
	<div style="clear: both;">&nbsp;</div>
</div>
<!-- end page -->

<?php include('footer.php'); ?>

</body>
</html>
<?php
mysql_free_result($csss);
?>